package br.com.abril.job;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class SchedulerController {

	@Autowired
	private Scheduler scheduler;
	
	@RequestMapping(value = "/rest/job/add", method = RequestMethod.POST)
	public List<Job> add(@RequestBody Job job) {
		return scheduler.registerJobsFromTemplate( job );
	}
	
	@RequestMapping(value = "/rest/job/scheduled", method = RequestMethod.GET)
	public List<Job> allScheduledJobs() {
		return scheduler.getAll().findAvailableToSchedule();
	}
	
	@RequestMapping(value = "/rest/job/all", method = RequestMethod.GET)
	public List<Job> all() {
		return scheduler.getAll().findByTemplateFalseAndActiveTrue();
	}	

	@RequestMapping(value = "/rest/job/restart", method = RequestMethod.GET)
	public void restart() {
		scheduler.reStartJobs();
	}	
		
	
}
